package com.wooming.studentinfosystem.controller;

import com.wooming.studentinfosystem.dto.StudentQueryDTO;
import com.wooming.studentinfosystem.service.impl.StudentQueryService;
import com.wooming.studentinfosystem.util.PageResult;
import com.wooming.studentinfosystem.util.Result;
import com.wooming.studentinfosystem.vo.StudentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Controller层: 学生信息查询
 *
 * @author wooming
 */
@RestController
@RequestMapping("/api/students")
public class StudentQueryController {

    @Autowired
    private StudentQueryService studentQueryService;

    @GetMapping
    public Result<PageResult<StudentVO>> getStudents(StudentQueryDTO params) {
        //前端连接测试用代码
//        System.out.println("前端发送分页查询请求");
//        System.out.println(params.getType());
//        System.out.println(params.getPageNum());
//        System.out.println(params.getPageSize());
//        System.out.println(params.getSort());
//        System.out.println(params.getOrder());

        // 参数校验
        if (params.getPageSize() > 100) {
            return Result.error(400, "每页数量不能大于100");
        }
        return Result.success(studentQueryService.getStudents(params));
    }
}
